// src/stores/modules/dashboard.ts
import { defineStore } from 'pinia'
import type { StatsData, ChartData, ActivityItem } from '@/types/dashboard'

export const useDashboardStore = defineStore('dashboard', {
  actions: {
    async getStats(): Promise<StatsData> {
      return new Promise((resolve) => {
        setTimeout(() => {
          resolve({
            userCount: Math.floor(Math.random() * 1000),
            orderCount: Math.floor(Math.random() * 500),
            salesAmount: Math.floor(Math.random() * 10000),
            todoCount: Math.floor(Math.random() * 20),
          })
        }, 300)
      })
    },
    
    async getCharts(): Promise<ChartData> {
      return new Promise((resolve) => {
        setTimeout(() => {
          resolve({
            visitTrend: Array(7).fill(0).map((_, i) => ({
              date: `10/${i + 1}`,
              count: Math.floor(Math.random() * 100)
            })),
            userSource: [
              { name: '直接访问', value: Math.floor(Math.random() * 100) },
              { name: '搜索引擎', value: Math.floor(Math.random() * 100) },
              { name: '社交媒体', value: Math.floor(Math.random() * 100) }
            ]
          })
        }, 200)
      })
    },
    
    async getActivities(): Promise<ActivityItem[]> {
      return new Promise((resolve) => {
        setTimeout(() => {
          resolve([
            { 
              id: 1, 
              user: '用户A', 
              action: '创建了订单 #1234', 
              time: '10分钟前' 
            },
            { 
              id: 2, 
              user: '用户B', 
              action: '更新了个人资料', 
              time: '30分钟前' 
            },
            { 
              id: 3, 
              user: '管理员', 
              action: '删除了评论', 
              time: '1小时前' 
            }
          ])
        }, 500)
      })
    }
  }
})